/**
 * Copyright (C), 2020-2020, 软件公司
 * FileName: Test
 * Author:   cakin
 * Date:     2020/5/5
 * Description:
 */
package com.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName: Test
 * @Description: TODO
 * @Date: 2020/5/5
 * @Author: cakin
 */
public class Test {
    private static final String EXCHANGE_NAME = "exchange_demo";
    private static final String ROUTING_KEY = "routingkey_demo";
    private static final String QUEUE_NAME = "queue_demo";
    private static final String IP_ADDRESS = "127.0.0.1";

    public static void main( String[] args ) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(IP_ADDRESS);
        factory.setUsername("root");
        factory.setPassword("123456");
        try {
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            channel.exchangeDeclare("source", "direct", false, true, null);
            channel.exchangeDeclare("destination", "fanout", false, true, null);
            channel.exchangeBind("destination", "source", "exKey");
            channel.queueDeclare("queue", false, false, true, null);
            channel.queueBind("queue", "destination", "");
            channel.basicPublish("source", "exKey", null, "exToExDemo".getBytes());

        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }


}
